package com.yugao.fintech.antelope.auth.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yugao.fintech.antelope.auth.service.ExtLdpService;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * 外部身份源
 */
@Api(tags = "外部身份源")
@RestController
@RequestMapping("/extLdp")
public class ExtLdpController {
    @Autowired
    private ExtLdpService extLdpService;

    @ApiOperation(value = "分页外部身份源")
    @GetMapping("/page")
    @RamResource(action = "auth:extLdp:query", name = "查询外部身份源", type = ActionType.READ)
    public Resp<IPage<ExtLdpResp>> pageExtLdp(@Validated ExtLdpPageReq req) {
        return Resp.ok(extLdpService.pageExtLdp(req));
    }

    @ApiOperation(value = "查询外部身份源")
    @GetMapping("/list")
    @RamResource(action = "auth:extLdp:query", name = "查询外部身份源", type = ActionType.READ)
    public Resp<List<ExtLdpResp>> listExtLdp(@Validated ExtLdpListReq req) {
        return Resp.ok(extLdpService.listExtLdp(req));
    }

    @ApiOperation(value = "通过id查找外部身份源")
    @GetMapping("/get")
    @RamResource(action = "auth:extLdp:query", name = "查询外部身份源", type = ActionType.READ)
    public Resp<ExtLdpResp> getExtLdp(@RequestParam(value = "code") String code) {
        return Resp.ok(extLdpService.getExtLdp(code));
    }
  
    @ApiOperation(value = "保存外部身份源")
    @PostMapping("/save")
    @RamResource(action = "auth:extLdp:save", name = "保存外部身份源", type = ActionType.WRITE)
    public Resp<?> saveExtLdp(@Validated @RequestBody ExtLdpSaveReq req) {
        return Resp.ok(extLdpService.saveExtLdp(req));
    }
  
    @ApiOperation(value = "更新外部身份源")
    @PostMapping("/update")
    @RamResource(action = "auth:extLdp:update", name = "更新外部身份源", type = ActionType.WRITE)
    public Resp<?> updateExtLdp(@Validated @RequestBody ExtLdpUpdateReq req) {
        return Resp.ok(extLdpService.updateExtLdp(req));
    }
  
    @ApiOperation(value = "批量删除外部身份源")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "auth:extLdp:delete", name = "删除外部身份源", type = ActionType.WRITE)
    public Resp<?> batchDeleteExtLdp(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(extLdpService.batchDeleteExtLdp(ids));
    }
  
    @ApiOperation(value = "删除外部身份源")
    @DeleteMapping("/delete")
    @RamResource(action = "auth:extLdp:delete", name = "删除外部身份源", type = ActionType.WRITE)
    public Resp<?> deleteExtLdp(@RequestParam(value = "id") Long id) {
        return Resp.ok(extLdpService.deleteExtLdp(id));
    }
}
